<template>
  <el-table :data="tableData" style="width: 100%">
    <el-table-column v-for="(value, key) in tableData[0] || {}" :key="key" :prop="key" :label="key" />
  </el-table>
</template>

<script setup>
import { ref, onMounted } from 'vue'
const data = ref([])
const tableData = [
  { name: '张三', age: 25, city: '北京' },
  { name: '李四', age: 30, city: '上海' }
]
// 模拟API请求
const fetchData = async () => {
  // 实际项目中替换为axios请求
  return await tableData
}

onMounted(async () => {
  try {
    data.value = await fetchData()
  } catch (e) {
    console.error('数据加载失败', e)
  }
})
</script>
